<template>
    <div>
        <CheckboxGroup v-model="rowData.checkAllGroup"
                       @on-change="checkAllGroupChange">
            <Checkbox v-for="(item,index) in rowData.selectValue"
                      :key="index"
                      :label="item.value">
                <span>{{item.label}}</span>
            </Checkbox>
        </CheckboxGroup>
    </div>
</template>
<script>
    export default {
        props: {
            index: Number,
            row: Object
        },
        data () {
            return {
                rowData: {}
            }
        },
        watch: {
            row (n, o) {
                this.rowData = n
            }
        },
        created () {
            this.rowData = this.row;
        },
        methods: {
            checkAllGroupChange (data) {
                if (data.length === this.rowData.selectValue.length) {
                    this.rowData.indeterminate = false;
                    this.rowData.isCheckAll = true;
                } else if (data.length > 0) {
                    this.rowData.indeterminate = true;
                    this.rowData.isCheckAll = false;
                } else {
                    this.rowData.indeterminate = false;
                    this.rowData.isCheckAll = false;
                }
                this.$emit('checkboxChange', this.rowData)
            }
        }
    }
</script>
